
import 'package:flutter_screenutil/screenutil.dart';
import 'package:flutter/material.dart';
import 'package:heyangkuaidai/DemonStrateModule/Components/NavigationBar.dart';
import 'package:heyangkuaidai/DemonStrateModule/LoanFirstPage.dart';
import 'package:heyangkuaidai/DemonStrateModule/LoanSelfHelpSendPage.dart';
import 'package:heyangkuaidai/DemonStrateModule/HoldLoanPage.dart';
import 'package:heyangkuaidai/DemonStrateModule/HomePage.dart';
class FirstPage extends StatefulWidget {
  @override
  _FirstPageState createState() => _FirstPageState();
}

class _FirstPageState extends State<FirstPage> {
  var nameList =["我要借款","放款","借款归还"];
  var infoList =["最高可借20万，线上放款，3分钟放款","一次申请，循环使用，自主发放，实时到帐","按日计息，整贷零还，无需预约，随用随还"];
  @override
  Widget build(BuildContext context) {
    ScreenUtil.init(context, width: 375, height: 667, allowFontScaling: true);
    return Scaffold(
        resizeToAvoidBottomInset: false,
      body:Column(
        children: [
          SizedBox(height: MediaQuery.of(context).padding.top,),
          NavigationBar( true,title: "福祥e贷",backCallback: (){
            Navigator.of(context).pushAndRemoveUntil(
              //跳转
                new MaterialPageRoute(builder: (context) => new HomePage()),
                //清除其他路由
                    (route) => route == null
            );
          },),
          SizedBox(height:ScreenUtil().setWidth(18) ,),
          Container(
            width: ScreenUtil.screenWidth,
            height: ScreenUtil.screenHeight-ScreenUtil().setWidth(82)-MediaQuery.of(context).padding.top,
            child: ListView.separated(
              // ignore: missing_return
              itemBuilder: (context, itemIndex){
                return InkWell(
                  onTap: (){
                    switch(itemIndex){
                      case 0:
                         Navigator.push(
                  context,
                  new MaterialPageRoute(
                    builder: (context) => new LoanFirstPage(),
                  ),
                );
                        break;
                      case 1:
                         Navigator.push(
                  context,
                  new MaterialPageRoute(
                    builder: (context) => new LoanSelfHelpSendPage(),
                  ),
                );
                        break;
                      case 2:
                         Navigator.push(
                  context,
                  new MaterialPageRoute(
                    builder: (context) => new HoldLoanPage(),
                  ),
                );

                        break;
                    }
                  },
                  child:firstItem(name: nameList[itemIndex],infoStr: infoList[itemIndex],index: itemIndex,) ,
                );



                // ignore: missing_return
              },separatorBuilder: (context, itemIndex){
              return Container(height: ScreenUtil().setWidth(20),);
            }, itemCount: 3,
              padding: EdgeInsets.only(left: ScreenUtil().setWidth(15),right: ScreenUtil().setWidth(15)),),
          ) ,
        ],
      )

    );

  }
}

class firstItem extends StatefulWidget {
  String name;
  String infoStr;
  int index;
  firstItem({this.name,this.infoStr,this.index,Key key}) : super(key: key);
  @override
  _firstItemState createState() => _firstItemState();
}

class _firstItemState extends State<firstItem> {

  @override
  Widget build(BuildContext context) {
    int itemIndex = widget.index;
    return
        Container(
          width: ScreenUtil.screenWidth-ScreenUtil().setWidth(30),
          height: ScreenUtil().setWidth(120),
          child: Image.asset("sources/yy/loan$itemIndex.png"),
        );


      Container(
       color:Colors.white,
       width: ScreenUtil.screenWidth-ScreenUtil().setWidth(30),
       height: ScreenUtil().setWidth(120),
       child: Row(
         children: [
           SizedBox(width:ScreenUtil().setWidth(17) ,),
           Image.asset("sources/qR.png",width: ScreenUtil().setWidth(48),height: ScreenUtil().setWidth(48),),
           SizedBox(width:ScreenUtil().setWidth(9) ,),
           Column(
             children: [
               SizedBox(height: ScreenUtil().setWidth(35),),
               Container(
                 width: ScreenUtil().setWidth(250),
                 child:Text(widget.name,style: TextStyle(fontSize: ScreenUtil().setSp(17),color: widget.index==0?Color(0xff398DC2):widget.index==1?Color(0xffF95274):Color(0xff0BE0B0)),textAlign: TextAlign.left,),
               ),
               SizedBox(height: ScreenUtil().setWidth(7),),
               Container(
                 width: ScreenUtil().setWidth(250),
                 child: Text(widget.infoStr,style: TextStyle(fontSize: ScreenUtil().setSp(13), ),textAlign: TextAlign.left),
               ),
             ],
           )
         ],
       ),
    );
  }
}
